capture log close
set more off

use "Couples_addhealth.dta", clear
sort aid

*Note: If using public data, gen bmi=(weight/totheight^2)*703

tab sex

/**dropping 4 obs where sex is not identified**/

drop if sex>2 

/**recoding the race variable to 0 if the answer is refused or don't know**/
replace hispanic=0 if hispanic>1
replace white=0 if white>1
replace black=0 if black>1
replace AI=0 if AI>1
replace asian=0 if asian>1
replace other=0 if other>1

recode appearance(6=.)
recode appearance(7=.)
recode appearance(8=.)
gen unattractive=0
replace unattractive=1 if (appearance==1|appearance==2)
gen attractive=1
replace attractive=0 if (appearance==1|appearance==2|appearance==3)
gen vattractive=1
replace vattractive=0 if (appearance>=1&appearance<=4)
gen ow=(bmi>25)

gen hs=(h4ed2>=3&h4ed2<=6)
gen coll=(h4ed2==7|h4ed2==8|h4ed2==12)
gen adv=(h4ed2==9|h4ed2==10|h4ed2==11|h4ed2==13)

/**AgeDiff = age of women minus age of man in first marriage**/

gen AgeDiff=agediff1*-1 if sex==1
replace AgeDiff=agediff1 if sex==2

gen negAgeDiff=AgeDiff*-1 

gen Pos=0 
replace Pos=1 if AgeDiff>0

gen Neg=0
replace Neg=1 if negAgeDiff>0

gen AgeDiff_Pos=AgeDiff*Pos
gen AgeDiff_Neg=negAgeDiff*Neg

gen ap=0 if (AgeDiff_Pos<=1&AgeDiff_Neg<=1)
replace ap=1 if (AgeDiff_Pos>=2&AgeDiff_Pos<=4)
replace ap=2 if (AgeDiff_Pos>=5)
replace ap=3 if (AgeDiff_Neg>=2&AgeDiff_Neg<=4)
replace ap=4 if (AgeDiff_Neg>=5)

replace age_mar1=. if age_mar1<16
replace age_mar1=. if age_mar1>34 /**this is due to errors in the original coding**/

summ bmi if sex==1
summ bmi if sex==2

tab appearance if sex==1
tab appearance if sex==2

gen agem2=age_mar1*age_mar1

reg bmi i.ap i.year_birth1 age_mar1 agem2 hispanic white black AI asian other hs coll adv if sex==1 [pw=wgt], robust
reg bmi i.ap i.year_birth1 age_mar1 agem2 hispanic white black AI asian other hs coll adv if sex==2 [pw=wgt], robust
logit attractive i.ap i.year_birth1 age_mar1 agem2 hispanic white black AI asian other hs coll adv if sex==1 [pw=wgt], robust
margins, dydx(ap) atmeans
logit attractive i.ap i.year_birth1 age_mar1 agem2 hispanic white black AI asian other hs coll adv if sex==2 [pw=wgt], robust
margins, dydx(ap) atmeans






















